<!DOCTYPE html>
<html>
{{template "bodyHead" `<link rel="stylesheet" type="text/css" href="/css/adminHome.css?v=1.0"/>`}}
<body>

{{template "inc_header" .}}

<div id="main">
    <div id="main-inner">

    {{template "adminMainInfo" .}}

    {{template "adminMainNav" "types"}}

        <div id="admin-types-main" class="clouds">
            <h3 class="clouds-title" id="admin-page-title">分类管理</h3>
            <div class="admin-types-main">
                <pre id="postTypesAll-pre">
                </pre>
            </div>
        </div>

    </div>
</div>

{{template "inc_footer" .}}
<script >
    $(function(){
        //获取所有分类
        $.ajax({
            url:"/admin/types/all",
            method:"GET",
            dataType:"json",
            success:function (d) {
                if (d.data.length<1){
                    alert("数据获取失败");
                    return;
                }

                str = "    <span>根分类</span><a href='javascript:(void:0);'>添加</a>\r\n";
                m = 0;
                for(var i in d.data){
                    n=0;
                    if ((m+1)==d.data.length){
                        str +="    <span>  └───["+d.data[i].post_num+"]<i _id='"+d.data[i].id+"' >"+d.data[i].name+"</i><a href='javascript:(void:0);'>添加</a><a href='javascript:(void:0);'>修改</a><a href='javascript:(void:0);'>删除</a></span>\r\n";
                        for (var x in d.data[i].child) {
                            if ((n+1)==d.data[i].child.length){
                                str +="    <span>           └───["+d.data[i].child[x].post_num+"]<i _id='"+d.data[i].child[x].id+"' >"+d.data[i].child[x].name+"</i><a href='javascript:(void:0);'>修改</a><a href='javascript:(void:0);'>删除</a></span>\r\n";
                            }else{
                                str +="    <span>           ├───["+d.data[i].child[x].post_num+"]<i _id='"+d.data[i].child[x].id+"' >"+d.data[i].child[x].name+"</i><a href='javascript:(void:0);'>修改</a><a href='javascript:(void:0);'>删除</a></span>\r\n";
                            }
                            n++;
                        }
                    } else{
                        str +="    <span>  ├───["+d.data[i].post_num+"]<i _id='"+d.data[i].id+"' >"+d.data[i].name+"</i><a href='javascript:(void:0);'>添加</a><a href='javascript:(void:0);'>修改</a><a href='javascript:(void:0);'>删除</a></span>\r\n";
                        for (var x in d.data[i].child) {
                            if ((n+1)==d.data[i].child.length){
                                str +="    <span>  │        └───["+d.data[i].child[x].post_num+"]<i _id='"+d.data[i].child[x].id+"' >"+d.data[i].child[x].name+"</i><a href='javascript:(void:0);'>修改</a><a href='javascript:(void:0);'>删除</a></span>\r\n";
                            }else{
                                str +="    <span>  │        ├───["+d.data[i].child[x].post_num+"]<i _id='"+d.data[i].child[x].id+"' >"+d.data[i].child[x].name+"</i><a href='javascript:(void:0);'>修改</a><a href='javascript:(void:0);'>删除</a></span>\r\n";
                            }
                            n++;
                        }
                    }
                    m++;
                }
                $('#postTypesAll-pre').html(str);
            }
        });
    });
</script>
</body>
</html>